
#include <Raknet/RakNetTypes.h>
#include <assert.h>
#include "wm_socket.h"
#include "wormnet/ISocketHander.h"

namespace worm
{

wmSocket::wmSocket()
{
    m_dwIndex = 0xffff;
    m_qwGUID -= m_qwGUID;
    m_pSocket = NULL;
    m_pSocketHandler = NULL;
    m_bClose = true;

    m_pRemoteAddr = new(RakNet::SystemAddress);
}

wmSocket::~wmSocket()
{
    delete (RakNet::SystemAddress*)m_pRemoteAddr;
    m_pRemoteAddr = NULL;
}

void wmSocket::SetRemoteAddr(const void* pAddr)
{
    assert(NULL != pAddr);
    *((RakNet::SystemAddress*)m_pRemoteAddr) = *((RakNet::SystemAddress*)pAddr);
}

const char* wmSocket::GetRemoteIp(void) const
{
    return ((RakNet::SystemAddress*)m_pRemoteAddr)->ToString(false);
}

uint16 wmSocket::GetRemotePort(void) const
{
    return ((RakNet::SystemAddress*)m_pRemoteAddr)->GetPort();
}

}
